let  app  =  getApp();
var  applet_park_api_url  =  app.globalData.applet_park_api_url;
var applet_park_api_url_imgUrl = app.globalData.applet_park_api_url_imgUrl;
const  {  
  requestDataparams
}  =  require('../../../utils/request.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    policyInfo: '',
    openId: '',
    nickName: '',
    imgUrl: applet_park_api_url_imgUrl,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    
    var that = this;
    var id = options.id;
    var openId = wx.getStorageSync("OPENID");
    var nickName = wx.getStorageSync("nickName");
    that.setData({
      id: id,
      openId: openId,
      nickName: nickName
    })

    that.getDetails()
  },
  getDetails() {
    var that = this;
    var url = "/api/information/queryIssueInformationById/" + that.data.id;  
    requestDataparams(url, {},  'POST', 'json').then(response => {
      if (response.data.code == 0) {
        that.setData({
          policyInfo: response.data.data
        })
      } else {
        wx.showToast({
          title: '失败',
          icon: 'none'
        })
      }    
    })
  },
  pay() {
    let that = this;
    var openId = wx.getStorageSync("OPENID");
    var TOKEN = wx.getStorageSync("TOKEN");
    wx.request({
      url: applet_park_api_url + '/api/unifiedOrder/createOrder',
      method: 'POST',
      header: {
        Authorization: TOKEN
      },
      data: {
        orderType: 6,
        totalMoney: that.data.price + '00', //that.data.price
        realityMoney: that.data.price + '00', //
        actId: that.data.id,
        openId: that.data.openId,
        nickName: that.data.nickName,
      },
      success(res2) {
        

        if (res2.data.code == 0) {

          
          
          
          
          wx.requestPayment({
            timeStamp: res2.data.data.timeStamp,
            nonceStr: res2.data.data.nonceStr,
            package: res2.data.data.prepay_id,
            signType: 'MD5',
            paySign: res2.data.data.sign,
            paySource: 1,
            success(res) {

              wx.showToast({
                title: '支付成功',
              })

              setTimeout(function() {
                wx.showToast({
                  title: '页面跳转中',
                })
                wx.navigateTo({
                  url: '../orderDetails_canteen/orderDetails_canteen?orderNo=' + that.data.orderNo,
                })

              }, 500);
            },
            fail(res3) {
              
            }
          })

        } else {
          wx.showToast({
            title: '网络异常',
          })
        }
      },
      fail(res) {
        wx.showToast({
          title: res.data,
        })
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})